//
//  PerformanceAgentTableViewCell.swift
//  kxf
//
//  Created by Mac on 2024/3/25.
//

import Foundation
import UIKit

class PerformanceAgentTableViewCell: UITableViewCell {
    
    var peizhiBlock:(()->())?
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .clear
        self.selectionStyle = .none
        initUI()
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(10)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        return vi
    }()
    lazy var avatarImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "performance_cell_avatar")
        
        return img
    }()
    lazy var nameLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        
        return lab
    }()
    lazy var showLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 14, weight: .regular)
        lab.text = "查看"
        return lab
    }()
    lazy var arrowImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "login_arrow_img")
        
        return img
    }()
    lazy var bgImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "performance_cell_bg_img")
        return img
    }()
    lazy var totalMoneyLabel : UILabel = {
        let lab = UILabel()
        lab.font = .systemFont(ofSize: 24, weight: .medium)
        lab.textColor = WHColor_16(colorStr: "FF7E00")
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var totalMoneyLab : UILabel = {
        let lab = UILabel()
        lab.font = .systemFont(ofSize: 14, weight: .medium)
        lab.textColor = .black
        lab.text = "交易总金额（元）"
        
        return lab
    }()
    lazy var lineView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        
        return vi
    }()
    lazy var tradeNumLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var tradeNumLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "服务商"
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rebateLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rebateLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "贡献收益（元）"
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var lineTwoView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        
        return vi
    }()
    lazy var mercNumLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var mercNumLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "商户"
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var iconImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "performance_cell_icon")
        return img
    }()
}

extension PerformanceAgentTableViewCell{
    func updateUI(dict:NSDictionary) {
        nameLabel.text = "\(dict["agentName"]as? String ?? "")团队"
        totalMoneyLabel.text = "\(dict["subTradeAmount"]as? Double ?? 0.00)"
        tradeNumLabel.text = "\(dict["subAgentNumber"]as? Int ?? 0)"
        rebateLabel.text = "\(dict["subProfit"]as? Double ?? 0.00)"
        mercNumLabel.text = "\(dict["subMerchantNumber"]as? Int ?? 0)"
    }
}

extension PerformanceAgentTableViewCell{
    func initUI() {
        contentView.addSubview(whiteView)
        whiteView.addSubview(avatarImgView)
        whiteView.addSubview(nameLabel)
        whiteView.addSubview(showLab)
        whiteView.addSubview(arrowImgView)
        
        whiteView.addSubview(bgImgView)
        bgImgView.addSubview(totalMoneyLabel)
        bgImgView.addSubview(totalMoneyLab)
        bgImgView.addSubview(lineView)
        bgImgView.addSubview(iconImgView)
        bgImgView.addSubview(tradeNumLabel)
        bgImgView.addSubview(tradeNumLab)
        bgImgView.addSubview(rebateLabel)
        bgImgView.addSubview(rebateLab)
        bgImgView.addSubview(lineTwoView)
        bgImgView.addSubview(mercNumLab)
        bgImgView.addSubview(mercNumLabel)
        
        setConstrait()
    }
    func setConstrait() {
        whiteView.snp.makeConstraints { make in
            make.left.top.width.equalToSuperview()
            make.height.equalTo(kFitWidth(206))
        }
        avatarImgView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(18))
            make.top.equalTo(kFitWidth(12))
            make.width.height.equalTo(kFitWidth(22))
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(avatarImgView.snp.right).offset(kFitWidth(3))
            make.centerY.lessThanOrEqualTo(avatarImgView)
            make.right.equalTo(kFitWidth(-75))
        }
        arrowImgView.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-13))
            make.centerY.lessThanOrEqualTo(avatarImgView)
            make.width.height.equalTo(kFitWidth(22))
        }
        showLab.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-44))
            make.centerY.lessThanOrEqualTo(avatarImgView)
        }
        bgImgView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(50))
            make.width.equalTo(kFitWidth(347))
            make.height.equalTo(kFitWidth(141))
        }
        totalMoneyLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(18))
            make.top.equalTo(kFitWidth(17))
            make.height.equalTo(kFitWidth(34))
            make.right.equalTo(kFitWidth(-50))
        }
        totalMoneyLab.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(18))
            make.top.equalTo(totalMoneyLabel.snp.bottom).offset(kFitWidth(2))
        }
        lineView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(111))
            make.top.equalTo(kFitWidth(87))
            make.width.equalTo(kFitWidth(1))
            make.height.equalTo(kFitWidth(17))
        }
        iconImgView.snp.makeConstraints { make in
            make.right.bottom.equalToSuperview()
            make.width.equalTo(kFitWidth(91))
            make.height.equalTo(kFitWidth(74))
        }
        tradeNumLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(8))
//            make.right.equalTo(lineView.snp.left).offset(kFitWidth(-8))
            make.width.equalTo(kFitWidth(95))
            make.top.equalTo(kFitWidth(77))
            make.height.equalTo(kFitWidth(28))
        }
        tradeNumLab.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualTo(tradeNumLabel)
            make.top.equalTo(tradeNumLabel.snp.bottom).offset(kFitWidth(2))
        }
        rebateLabel.snp.makeConstraints { make in
            make.left.equalTo(lineView.snp.right).offset(kFitWidth(8))
            make.centerY.lessThanOrEqualTo(tradeNumLabel)
            make.width.equalTo(tradeNumLabel)
        }
        rebateLab.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualTo(rebateLabel)
            make.centerY.lessThanOrEqualTo(tradeNumLab)
        }
        lineTwoView.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-112))
            make.centerY.lessThanOrEqualTo(lineView)
            make.width.height.equalTo(lineView)
        }
        mercNumLabel.snp.makeConstraints { make in
            make.left.equalTo(lineTwoView.snp.right).offset(kFitWidth(8))
            make.width.equalTo(rebateLabel)
            make.centerY.lessThanOrEqualTo(rebateLabel)
        }
        mercNumLab.snp.makeConstraints { make in
            make.centerY.lessThanOrEqualTo(rebateLab)
            make.centerX.lessThanOrEqualTo(mercNumLabel)
        }
    }
}
